﻿using NHibernate;
using System;
using System.Collections.Generic;
using System.Linq;

namespace NHibernateExample.Models
{
    public class Lists
    {
        /// <summary>
        /// Display all lists
        /// Todo! Using static methods like this is an awful approach
        /// </summary>
        /// <param name="session"></param>
        public static void Read(ISession session)
        {
            ISQLQuery query = session.CreateSQLQuery("SHOW LISTS").AddEntity(typeof(Content.Lists));
            IList<Content.Lists> results = query.List<Content.Lists>();

            if (results.Any())
            {
                Console.WindowWidth = 90;
                const string header = "{0,-38} {1,-23} {2,-11} {3}";
                Console.WriteLine(header, "ID", "Title", "Created", "ItemCount");
                foreach (Content.Lists item in results)
                {
                    Console.WriteLine(header, item.ID, item.Title, item.Created.ToShortDateString(), item.ItemCount);
                }
            }
            else
            {
                Console.WriteLine("Could not fetch any lists");
            }
        }
    }
}
